<template>
      <div class="zb_nr">
        <el-dialog title="招标信息" :visible.sync="dialogFormVisible" width="80%">
          <el-form :model="form">
            <el-form-item label="项目名称：" :label-width="formLabelWidth">
              <div class="xians">{{ form.projectName }}</div>
            </el-form-item>
            <el-form-item label="招标公司：" :label-width="formLabelWidth">
              <div class="xians">{{ form.name }}</div>
            </el-form-item>
            <el-form-item label="公司法人：" :label-width="formLabelWidth">
              <div class="xians">{{ form.peopleName }}</div>
            </el-form-item>
            <el-form-item label="项目报价：" :label-width="formLabelWidth">
              <div class="xians">{{ form.price }}万元</div>
            </el-form-item>
            <el-form-item label="更新时间：" :label-width="formLabelWidth">
              <div class="xians">{{ form.updateTime }}</div>
            </el-form-item>
            <el-form-item label="结束时间：" :label-width="formLabelWidth">
              <div class="xians">{{ form.endTime }}</div>
            </el-form-item>
            <el-form-item label="项目说明：" :label-width="formLabelWidth">
              <div class="ex" v-html="form.ex"></div>
            </el-form-item>
          </el-form>
          <div slot="footer" class="dialog_footer">
              <div v-if="form.pass === '0'">
                <el-button @click="changePsss(form)" size="mini" type="danger">
                  通过
                </el-button>
                <el-button @click="changeUnPsss(form)" size="mini" type="danger">
                  不通过
                </el-button>
              </div>
              <div v-else-if="form.pass === '1'" class="pass">已通过</div>
              <div v-else-if="form.pass === '-1'" class="unPass">不通过</div>
          </div>
        </el-dialog>
        <el-table :data="zbUnArr" class="table">
          <el-table-column prop="projectName" label="项目名称" fixed="left" width="250px"></el-table-column>
          <el-table-column prop="name" label="公司名称" width="250px"></el-table-column>
          <el-table-column prop="peopleName" label="公司法人"></el-table-column>
          <el-table-column prop="phone" label="联系电话" width="120px"></el-table-column>
          <el-table-column prop="price" label="项目报价（万元）" sortable width="160px"></el-table-column>
          <!-- <el-table-column prop="ex" label="项目说明" width="200px"></el-table-column> -->
          <el-table-column prop="updateTime" label="更新时间" sortable width="180px"></el-table-column>
          <el-table-column prop="endTime" label="结束时间" sortable width="180px"></el-table-column>
          <el-table-column fixed="right"  label="审核信息" width="120px">
              <template slot-scope="scope">
                <el-button @click="shenH(scope.row)" type="primary">去审核</el-button>
              </template>
          </el-table-column>
          <!-- <el-table-column fixed="right"  label="审核信息" width="180px">
            <template slot-scope="scope">
              <div v-if="scope.row.pass === '0'">
                <el-button @click="changePsss(scope.row)" size="mini" type="danger">
                  通过
                </el-button>
                <el-button @click="changeUnPsss(scope.row)" size="mini" type="danger">
                  不通过
                </el-button>
              </div>
              <div v-else-if="scope.row.pass === '1'" class="pass">已通过</div>
              <div v-else-if="scope.row.pass === '-1'" class="unPass">不通过</div>
            </template>
          </el-table-column> -->
        </el-table>
        <el-pagination background layout="prev, pager, next" @current-change="changePage" :current-page="1" :page-count="page"></el-pagination>
      </div>
</template>

<script>
// 招标发布审核
import { Notification } from 'element-ui'
import { getInsertAll, updateCheck, getByProjectName } from '@/api/zbUn'
import { getSysUser } from '@/api/user'
export default {
  name: 'ZbInsertIndex',
  data () {
    return {
      page: 0,
      zbUnArr: [],
      dialogFormVisible: false,
      formLabelWidth: '10%',
      form: {
        projectName: '',
        name: '',
        peopleName: '',
        phone: '',
        price: undefined,
        ex: '',
        updateTime: '',
        endTime: '',
        pass: undefined
      }
    }
  },
  props: {
    search: {
      type: String
    }
  },
  computed: {
    name () {
      return this.$store.getters.name
    }
  },
  async created () {
    const res = await getSysUser(this.name)
    this.user = res.data
    if (this.user.admin1 !== 1 && this.user.admin3 !== 1) {
      this.$message({
        message: '暂无该权限',
        type: 'error'
      })
      this.$store.commit('zbUn/setSearchInfo', { search: '', show: 1 })
      this.$router.replace('/login')
    }
    if (this.search !== null && this.search !== '') {
      const res = await getByProjectName(this.search)
      if (res.isSuccess) {
        this.zbUnArr = res.data
      }
    } else {
      const { data: { records, pages } } = await getInsertAll()
      this.zbUnArr = records
      this.page = pages
    }
  },
  methods: {
    show (res) {
      if (res.isSuccess) {
        Notification({
          title: res.message + ' 请注意刷新',
          type: 'success'
        })
      } else {
        Notification({
          title: res.message + ' 请注意刷新',
          type: 'error'
        })
      }
    },
    async changePsss (row) {
      const res = await updateCheck({ id: row.id, pass: '1' })
      this.show(res)
      this.$router.go()
    },
    async changeUnPsss (row) {
      const res = await updateCheck({ id: row.id, pass: '-1' })
      this.show(res)
      this.$router.go()
    },
    async changePage (page) {
      const { data: { records } } = await getInsertAll(page)
      this.zbUnArr = records
    },
    shenH (row) {
      this.form = row
      this.dialogFormVisible = true
    }
  }
}
</script>

<style lang="less" scoped>
.xians {
  text-align: left;
}
.ex {
  width: 90%;
  padding: 2%;
  border: 1px solid;
}
.dialog_footer {
  height: 3rem;
  line-height: 3rem;
  text-align: center;
}
  .zb_nr {
    width: 100%;
    border-top: 1px solid;
    .table {
      width: 95%;
      margin-left: 2%;
      margin-bottom: 2%;
    }
  }
.pass {
  color: red;
}
.unPass {
  color: rgb(193, 193, 193);
}
.success {
  background-color: rgb(47, 255, 0);
  color: black;
}
</style>
